/*
Copyright 2010 Sieric
http://sieric.ca

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package savior.messaging;

import java.util.ArrayList;

public class Manager implements Logger {

    private static Manager instance;
    private ArrayList<Logger> loggerList = new ArrayList<Logger>();
    private boolean enableDebug = false;

    private Manager() {
    }

    public static Manager getInstance() {
        if (instance == null) {
            instance = new Manager();
        }
        return instance;
    }

    public void addLogger(Logger log) {
        loggerList.add(log);
    }

    public void enableDebug(boolean enabled) {
        enableDebug = enabled;
    }

    public void replaceLoggers(Logger log) {
        loggerList.clear();
        loggerList.add(log);
    }

    @Override
    public void action(String text) {
        for (Logger l : loggerList) {
            l.action(text);
        }
    }

    @Override
    public void debug(String text) {
        if (!enableDebug) {
            return;
        }

        for (Logger l : loggerList) {
            l.debug(text);
        }
    }

    @Override
    public void error(String text) {
        for (Logger l : loggerList) {
            l.error(text);
        }
    }

    @Override
    public void information(String text) {
        for (Logger l : loggerList) {
            l.information(text);
        }
    }
}
